package com.shouxue.pagerv;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RsdTitleAdapter extends RecyclerView.Adapter<RsdTitleAdapter.RsdTitleViewHolder> {
    private Context mContext;
    private int type;

    public RsdTitleAdapter(Context mContext,int type) {
        this.mContext = mContext;
        this.type=type;
    }

    @NonNull
    @Override
    public RsdTitleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_layout,parent,false);;
        if (type==1){
            view = LayoutInflater.from(mContext).inflate(R.layout.item_layout_half,parent,false);
        }
        return new RsdTitleViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RsdTitleViewHolder holder, int position) {
        holder.tv.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        if (list==null){
            return 0;
        }
        return list.size();
    }

    private List<String> list;
    public void setData(List<String> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    class RsdTitleViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;
        public RsdTitleViewHolder(@NonNull View itemView) {
            super(itemView);
            iv=itemView.findViewById(R.id.iv);
            tv=itemView.findViewById(R.id.tv);
        }
    }
}
